package popcorn.ticket.job;

import java.util.Date;
import java.util.List;
import java.util.TimerTask;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import popcorn.ticket.entity.Orders;
import popcorn.ticket.serviceimpl.OrdersServiceImpl;
import popcorn.ticket.tool.GetEndTimeTools;

public class timerJobTest extends TimerTask{
	
	// 这里自动判断支付时间
	
	@Override
	public void run() {
		
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");	
	
		OrdersServiceImpl osi = context.getBean(OrdersServiceImpl.class);
		
		List<Orders> list = osi.getAllOrders();
		
		for (Orders orders : list) {

			// 当还有订单未支付时 判断支付时间是否超过 超过则将状态修改未已取消 
			if(orders.getPaytime() == null && orders.getOrderstatus() == 2) {
				//支付的最后时间
				Date endTime=GetEndTimeTools.getEndDate(orders.getOrdertime(), 15);
				
				long endpaytime=endTime.getTime();
				
				Date now = new Date();
				long nowpaytime=now.getTime();
				
				if (endpaytime-nowpaytime>0) {

				}else {

					orders.setOrderstatus(0);
					osi.updOrders(orders);
				}
			}
		}
		context.close();
	}
}
